'''
Created on Mar 1, 2020
Pytorch Implementation of LightGCN in
Xiangnan He et al. LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation

@author: Jianbai Ye (gusye@mail.ustc.edu.cn)
'''

import os
from os.path import join
import torch
from enum import Enum
from parse import parse_args
import multiprocessing

os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
#把我们的命令行参数赋值给args
args = parse_args()
"""
os.path.dirname(__file__): 这会返回当前文件的目录名。
__file__的值是'D:\\project\\LightGCN-PyTorch-master\\code\\world.py'，那么os.path.dirname(__file__)的值就是'D:\\project\\LightGCN-PyTorch-master\\code'
os.path.dirname(os.path.dirname(__file__)): 这会返回上一步返回的路径的上级目录。继续上面的例子，它返回的是'D:\\project\\LightGCN-PyTorch-master'。
"""
ROOT_PATH = os.path.dirname(os.path.dirname(__file__))
#将ROOT_PATH和code拼接在一起
CODE_PATH = join(ROOT_PATH, 'code')
DATA_PATH = join(ROOT_PATH, 'data')
BOARD_PATH = join(CODE_PATH, 'runs')
FILE_PATH = join(CODE_PATH, 'checkpoints')
import sys
#这行代码是在Python中向sys.path列表添加一个新的路径，这样Python解释器在查找模块和包时就会包括这个新路径。
sys.path.append(join(CODE_PATH, 'sources'))


if not os.path.exists(FILE_PATH):
    os.makedirs(FILE_PATH, exist_ok=True)


config = {}
all_dataset = ['lastfm', 'gowalla', 'yelp2018', 'amazon-book']
all_models  = ['mf', 'lgn']
# config['batch_size'] = 4096
#batch数量
config['bpr_batch_size'] = args.bpr_batch
#embedding维度
config['latent_dim_rec'] = args.recdim
#LGCN运行轮数
config['lightGCN_n_layers']= args.layer
#丢弃率
config['dropout'] = args.dropout
#bpr评估的batchsize
config['keep_prob']  = args.keepprob
#该参数用于指定如何分割大型邻接矩阵。如果没有提供该参数的值，其默认值为100
config['A_n_fold'] = args.a_fold
#测试时的batch大小
config['test_u_batch_size'] = args.testbatch
#是否使用多线程运行测试集
config['multicore'] = args.multicore
#学习率
config['lr'] = args.lr
#l2正则化惩罚力度
config['decay'] = args.decay
#是否使用已经训练好的数据集
#config['pretrain'] = True
config['pretrain'] = args.pretrain
config['A_split'] = False
config['bigdata'] = False
#测试cuda是否可用
GPU = torch.cuda.is_available()
device = torch.device('cuda' if GPU else "cpu")
#获取cpu的核心数量
CORES = multiprocessing.cpu_count() // 2
#获取随机种子
seed = args.seed
#获取数据集 默认是gowalla
# dataset = "lastfm"
dataset = args.dataset
#选择模型 默认是lgn
model_name = args.model
if dataset not in all_dataset:
    raise NotImplementedError(f"Haven't supported {dataset} yet!, try {all_dataset}")
if model_name not in all_models:
    raise NotImplementedError(f"Haven't supported {model_name} yet!, try {all_models}")



#获取训练轮数 默认1000
TRAIN_epochs = args.epochs
#是否加载 是否加载默认不加载
LOAD = args.load
#保存参数的位置 默认在./checkpoints
PATH = args.path
#topk推荐 eval:如果args.topks是字符串'3'，那么eval(args.topks)将返回整数3
topks = eval(args.topks)
#是否开启tensorboard 用于数据可视化默认是开启
tensorboard = args.tensorboard
#默认comment为lgn
comment = args.comment
# let pandas shut up
from warnings import simplefilter
#对于所有的 FutureWarning，Python 不会显示任何警告信息
simplefilter(action="ignore", category=FutureWarning)


#该方法用于改变字符输出的颜色
def cprint(words : str):
    print(f"\033[0;30;43m{words}\033[0m")

logo = r"""
██╗      ██████╗ ███╗   ██╗
██║     ██╔════╝ ████╗  ██║
██║     ██║  ███╗██╔██╗ ██║
██║     ██║   ██║██║╚██╗██║
███████╗╚██████╔╝██║ ╚████║
╚══════╝ ╚═════╝ ╚═╝  ╚═══╝
"""
# font: ANSI Shadow
# refer to http://patorjk.com/software/taag/#p=display&f=ANSI%20Shadow&t=Sampling
# print(logo)
